package com.laolei.core.web.config;

import java.util.Map;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.session.data.redis.RedisOperationsSessionRepository;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

import com.laolei.core.redis.RedisTemplatePackage;

@Configuration
@ConditionalOnClass(RedisOperationsSessionRepository.class)
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 1800)
public class SessionConfig {
	
	@Bean
	public <S extends Session> SessionRepository<?> sessionRepository(Map<Integer,RedisTemplatePackage> redisTemplatePackages) {
		 @SuppressWarnings("rawtypes")
		RedisTemplate redisTemplate = redisTemplatePackages.get(4).getRedisTemplate();
		@SuppressWarnings("unchecked")
		RedisOperationsSessionRepository sessionRepository = new RedisOperationsSessionRepository(redisTemplate);
		return sessionRepository;
	}
}
